﻿function prefix(i) {
    if (i < 10) {
        return "0" + i;
    } else {
        return i;
    }
}
function formatNoon(hour) {
    if (hour == 0) {
        return " 午夜 ";
    } else if (hour < 6) {
        return " 凌晨 ";
    } else if (hour < 12) {
        return " 上午 ";
    } else if (hour == 12) {
        return " 正午 ";
    } else if (hour < 18) {
        return " 下午 ";
    } else {
        return " 晚上 ";
    }
}
function initArray() {
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++) {
        this[i + 1] = initArray.arguments[i];
    }
}
function tick() {
    var now = new Date();
    var week = new initArray(
       " 星期日",
       " 星期一",
       " 星期二",
       " 星期三",
       " 星期四",
       " 星期五",
       " 星期六"
    );
    timeString = now.getFullYear() + "年" + prefix(now.getMonth() + 1) + "月" + prefix(now.getDate()) + "日" + week[now.getDay() + 1] + formatNoon(now.getHours()) + prefix(now.getHours()) + ":" + prefix(now.getMinutes()) + ":" + prefix(now.getSeconds());
    $("#clock").html(timeString);
    window.setTimeout("tick();", 1000);
}
$(function () {
    tick();
})